<?php
class theme extends template
{

	public function __construct()
	{
		$this->north = true;		//顶部
		$this->west = true;			//左部
		$this->center = true;		//中部
		$this->east = false;		//无右部
		$this->south = true;		//底部
	}

	// head 头， 用于子类添加js和css
	protected function head(){}
	
	
	public function display()
	{
		$my = bone::get_user();
		$config = bone::get_config('system');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="description" content="<?php echo $this->get_meta_description();?>">
<meta http-equiv="keywords" content="<?php echo $this->get_meta_keyword();?>">
<title><?php echo $this->get_title().' - '.$config->site_name; ?></title>

<script type="text/javascript" language="javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" language="javascript">$.ajaxSetup({cache: false});</script>

<link type="text/css" rel="stylesheet" href="css/global.css">
<script type="text/javascript" language="javascript" src="js/global.js"></script>

<?php if(!$my->guest && ($my->is_admin || $my->is_developer) ){?>
<script type="text/javascript" language="javascript" src="js/heartbeat.js"></script>
<?php } ?>

<link type="text/css" rel="stylesheet" href="themes/default/css/theme.css">
<?php $this->head();?>

</head>

<body>

<div class="theme-body">
<div class="theme-body-bg-l">
<div class="theme-body-bg-r">
<?php $this->body();?>
</div>
</div>
</div>

</body>
</html>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-8956543-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
<?php
	}

	protected function body()
	{
	?>
<div class="theme-north">
	<?php $this->north(); ?>
</div>

<div class="theme-middle">
	<?php $this->middle(); ?>
</div>

<div class="theme-south">
	<?php $this->south(); ?>
</div>
	<?php
	}
	
	protected function north()
	{
	$config = bone::get_config('system');
	?>

<div class="logo">
	<img src="images/logo.gif" alt="<?php echo $config->site_name; ?>" />
</div>

<div class="menu">
	<ul>
		<?php
		$menu_id = $this->get('menu_id');
		$main_menu_tree = $this->get('main_menu_tree');

		if(count($main_menu_tree))
		{
			foreach($main_menu_tree as $menu)
			{
				if(!$menu_id) $menu_id = $menu->id;
				
				if($menu_id == $menu->id)
					echo '<li class="menu-on">';
				else
					echo '<li class="menu-off">';
				echo '<a href="'.url($menu->url).'"><span>'.$menu->name.'</span></a>';
				echo '</li>';
			}
		}
		?>
	</ul>
</div>

<div class="clrl"></div>

	<?php
	}



	// 网页的中部
	protected function middle()
	{
	?>
<div class="theme-west">
	<div class="wraper">
		<?php $this->west(); ?>
	</div>
</div>

<div class="theme-center">
	<div class="wraper">
	<?php $this->center(); ?>
	</div>
</div>

<div class="clr"></div>
	<?php
	}

	// 南部 即网页底部
	protected function south()
	{
	
		$foot_menu_tree = $this->get('foot_menu_tree');
		$config = bone::get_config('system');
	
		if(count($foot_menu_tree))
		{
			echo '<div class="foot-menu">';
			echo '<ul>';
			$i=1;
			$n=count($foot_menu_tree);
			foreach($foot_menu_tree as $menu)
			{
				echo '<li><a href="'.url($menu->url).'"><span>'.$menu->name.'</span></a></li>';
				if($i<$n) echo '<li>|</li>';
				$i++;
			}
			echo '</ul>';
			echo '</div>';
		}
		
		/* 免费使用骨头系统， 请保留 www.mrbone.org 链接 */
	?>
<div class="copyright clr">
&copy;2010 - 版权所有: <?php echo $config->site_name; ?><br />
ICP备案号: <a href="http://www.miibeian.gov.cn/" target="_blank">豫ICP备10207586号</a>
</div>
	<?php
	}
	
	
	
	// 主体的西部， 即网页主休的左部
	protected function west()
	{
	$my = bone::get_user();
	?>
<div class="west-title">用户登陆</div>
<div class="west-content">

<?php if($my->guest){?>
<ul class="login-form">
<form action="./" method="post" onsubmit="javascript: return $('#west-username').val()!='' && $('#west-password').val()!=''  ">
<li><label>用户名: </label><input type="text" name="username" id="west-username" /></li>
<li><label>密码: </label><input type="password" name="password" id="west-password" /></li>
<li><label>记住我: </label><input type="checkbox" name="rememberme" value="1"></li>
<li><label>&nbsp;</label><input type="submit" value="登陆"/> 
<a href="<?php echo url('./?controller=user&task=register'); ?>">注册</a>  
<a href="<?php echo url('./?controller=user&task=forget_password'); ?>">忘记密码?</a></li>
<input type="hidden" name="controller" value="user" />
<input type="hidden" name="task" value="login_check" />
</form>
</ul>
<?php }else{ ?>
<p>你好, <?php echo $my->username; ?></p>
<p><a href="<?php echo url('./?controller=user&task=edit'); ?>">修改资料</a> <a href="<?php echo url('./?controller=user&task=reset_password'); ?>">修改密码</a></p>
<p><input type="button" value="退出" onclick="javascript:window.location.href='<?php echo url('./?controller=user&task=logout'); ?>';"/></p>
<?php
}
?>
</div>

<div class="west-content">
<a href="http://www.mrbone.org" target="_blank" title="点击访问骨头系统官网">
<img src="themes/default/images/mrbone.gif" alt="骨头系统1.2发布了" width="200" height="120" border="0">
</a>
</div>

<div class="west-title">支持的技术</div>
<div class="west-content">
	<div class="techniques">
	<ul>
	<li><img src="themes/default/images/w3c.gif" alt="W3C HTML, CSS" width="90" height="40"></li>
	<li><img src="themes/default/images/javascript.gif" alt="Javascript" width="90" height="40"></li>
	<li><img src="themes/default/images/asp.gif" alt="ASP" width="90" height="40"></li>
	<li><img src="themes/default/images/asp.net.gif" alt="ASP.NET" width="90" height="40"></li>
	<li><img src="themes/default/images/php.gif" alt="PHP" width="90" height="40"></li>
	<li><img src="themes/default/images/java.gif" alt="JAVA/JSP/J2SE" width="90" height="40"></li>
	<li><img src="themes/default/images/mysql.gif" alt="MySQL数据库" width="90" height="40"></li>
	<li><img src="themes/default/images/mssql.gif" alt="MSSQL数据库" width="90" height="40"></li>
	<li><img src="themes/default/images/oracle.gif" alt="Oracle数据库" width="90" height="40"></li>
	<li></li>
	<li><img src="themes/default/images/jquery.gif" alt="轻量级JS框架JQuery" width="90" height="40"></li>
	<li><img src="themes/default/images/mootools.gif" alt="轻量级JS框架Mootools" width="90" height="40"></li>
	</ul>
	</div><div class="clrl"></div>
</div>



<div class="west-title">浏览器兼容</div>
<div class="west-content">
	<div class="browsers">
	<ul>
	<li><img src="themes/default/images/ie.gif" alt="IE 7/8/9" width="32" height="32"></li>
	<li><img src="themes/default/images/firefox.gif" alt="Firefox" width="32" height="32"></li>
	<li><img src="themes/default/images/chrome.gif" alt="Chrome" width="32" height="32"></li>
	<li><img src="themes/default/images/safari.gif" alt="Safari" width="32" height="32"></li>
	<li><img src="themes/default/images/opera.gif" alt="Opera" width="32" height="32"></li>
	</ul>
	</div><div class="clrl"></div>
</div>


<?php
	}
	
	
	protected function message()
	{
		$message = $this->get('controller.message');
		if($message)
		{
			echo '<div class="message-'.$message->type.'">'.$message->body.'</div>';
		}
	}
	
	public function pagination()
	{
		$pagination = $this->get_pagination();
		
		$total = $pagination->get_total();
		$pages = $pagination->get_pages();
		$limit = $pagination->get_limit();
		$page = $pagination->get_page();
		$url = $pagination->get_url();
		
		if($pages>1)
		{
			echo '<div class="pagination">';
			if($page == 1)
			{
				echo '<span class="first">&lt;&lt;</span>';
				echo '<span class="pre">&lt;</span>';
			}
			else
			{
				echo '<span class="first"><a href="'.$url.'page=1">&lt;&lt;</a></span>';
				echo '<span class="pre"><a href="'.$url.'page='.($page-1).'">&lt;</a></span>';
			}
	
			echo '<span class="current">'.$page.'/'.$pages.'</span>';
	
			if($page < $pages)
			{
				echo '<span class="next"><a href="'.$url.'page='.($page+1).'">&gt;</a></span>';
				echo '<span class="last"><a href="'.$url.'page='.$pages.'">&gt;&gt;</a></span>';
			}
			else
			{
				echo '<span class="next">&gt;</span>';
				echo '<span class="last">&gt;&gt;</span>';
			}
			
			echo '<span class="goto">';
			echo '<select onchange="javascript:window.location.href=\''.$url.'page=\'+this.options[this.selectedIndex].value;">';
			for($i=1; $i<=$pages; $i++)
			{
				echo '<option value="'.$i.'"';
				if($i == $page) echo ' selected';
				echo '>'.$i.'</option>';
			}
			echo '</select>';
			echo '</span>';
			echo '</div>';
		}
	}
	

	public function load_editor()
	{
	$this->editor = true;
	?>
<script type="text/javascript" src="js/tiny_mce/jquery.tinymce.js"></script>
<script type="text/javascript">
	$().ready(function() {
		$('textarea.editor').tinymce({
			script_url : 'js/tiny_mce/tiny_mce.js',
			language : "zh",
			theme : "advanced",
			
			force_p_newlines : false, 
			force_br_newlines : true, 
			remove_linebreaks : false,
			button_tile_map : true,

			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,|,bullist,numlist,|,forecolor,backcolor,fontselect,fontsizeselect,|,removeformat",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			theme_advanced_fonts : "黑体=黑体;楷体=楷体;仿宋=仿宋;隶书=隶书;幼圆=幼圆;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats",

			
			font_size_style_values : "8px,10px,12px,14px,18px,24px,36px",
			content_css : "css/content.css"		
		});
	});
</script>
	<?php
	}	


	public function editor($editor_name, $value='', $width='100%', $height='200px')
	{
		if(!$this->editor) $this->load_editor();
		echo '<textarea name="'.$editor_name.'" id="'.$editor_name.'" class="editor" style="width:'.$width.';height:'.$height.';">'.htmlspecialchars($value).'</textarea>';
	}

}

?>
